<template>
    <div>
        <div class="page-bg"></div>
        <div class="standard-wrap">
            <div class="item-wrap">
                <standardItem :item="arr2"
                              :selectStandard="selectStandard"></standardItem>
            </div>
        </div>
        <myMenu @clickBack="back"></myMenu>
    </div>
</template>
<script>
import standardItem from './select'
import { Checklist } from 'vux'
import myMenu from '@/commonComponents/menu'
export default {
    components: {
        Checklist,
        myMenu,
        standardItem
    },
    data () {
        return {
            commonList: ['China', 'Japan', 'America'],
            checklist: [],
            parmas: {
                allowPaging: 'true',
                business: 'FetchHiddenDangerStandards',
                data: {
                    ProjectId: ''
                },
                pageIndex: 0,
                pageSize: 20000,
                tokenId: 'A3944C2D655B11D684296E71CB81C9BD',
                userId: ''
            },
            arr1: [],
            arr2: [],
            memberWorkArr: [],
            memberWorkIdArr: [],
            obj: {},
            obj2: {},
            name2: '',
            id2: '',
            index: 0,
        }
    },
    created () {

    },
    mounted () {
        var token = JSON.parse(window.localStorage.getItem('userInfo'))
        this.index = this.$route.query.index
        this.parmas.userId = token.userid
        this.parmas.data.ProjectId = token.deptid
        this.dataArr()
    },
    methods: {
        selectStandard (item) {
            item.checked = !item.checked
            var str1 = ''
            var str2 = ''
            var reg = new RegExp('undefined', 'g')
            for (var k of this.arr2) {
                if (k.checked) {
                    str1 += k.DeptName + '_'
                    str2 += k.DeptId + '_'
                }
            }
            var a = str1.replace(reg, '')
            this.name2 = a.slice(0, a.length - 1) //保存名字
            var b = str2.replace(reg, '')
            this.id2 = b.slice(0, b.length - 1) //对应id
        },
        back () {
            var name2 = sessionStorage.getItem('name2') ? JSON.parse(sessionStorage.getItem('name2')) : []
            if (this.name2 != "") {
                name2.splice(this.index, 1, this.name2)
                window.sessionStorage.setItem('name2', JSON.stringify(name2))
            }
            var id2 = sessionStorage.getItem('id2') ? JSON.parse(sessionStorage.getItem('id2')) : []
            if (this.id2 != "") {
                id2.splice(this.index, 1, this.id2)
                window.sessionStorage.setItem('id2', JSON.stringify(id2))
            }
        },
        dataArr () {
            this.$axiosAjax.getConfigJson(this.parmas).then((res) => {
                if (res.status) {
                    if (res.data.data) {
                        for (var k of res.data.data) {
                            this.arr1.push(k.DeptName)
                        }
                        var arr2 = []
                        res.data.data.forEach(item => {
                            item.checked = false
                            arr2.push(item)
                        })
                        this.arr2 = arr2
                    }
                }
            })
        }
    }
}

</script>
<style lang="less" scoped>
.demo8 {
    width: 100%;
    height: 100%;
    .header {
        width: 100%;
        height: 40px;
        line-height: 40px;
        text-align: center;
        position: relative;
        font-size: 18px;
        background: #2269ff;
        color: #fff;
        .vux-x-icon {
            fill: cornsilk;
            position: absolute;
            left: 0;
            top: 5px;
            width: 30px;
            height: 30px;
        }
    }
    .demo8_main {
        height: 603px;
        width: 100%;
        background-color: #ebeef2;
        .list3Box {
            width: 100%;
            height: 603px;
            background-color: #fff;
            ul {
                padding: 0 10px;
                li {
                    height: 60px;
                    line-height: 60px;
                    font-size: 20px;
                    border-bottom: 1px solid #999;
                }
            }
        }
    }
    .weui-check_label {
        width: 100%;
        height: 44px;
        background-color: pink;
    }
}
</style>
